<block name="phpscript">
 <php>$submenus=$menus;</php>

    <php>function getsubmenu($submenus){</php>
    <notempty name="submenus">
        <php>foreach($submenus as $menu){</php>
            <li class="nav-item">
                <php>
                    $menu_name=lang($menu['lang']);
                    $menu_name=$menu['lang']==$menu_name?$menu['name']:$menu_name;
                </php>

                <php>if(empty($menu['items'])){</php>

                    <a href="javascript:openapp('{$menu.url}','{$menu.id}','{$menu_name}',true);" class="nav-link">
                        <i class="material-icons">library_books</i>
                        <span class="menu-text"> {$menu_name} </span>
                    </a>
                <php>}else{</php>

                    <a href="#" class="nav-link dropdown-toggle">
                        <i class="material-icons">library_books</i>
                        <span class="menu-text normal"> {$menu_name} </span>
                    </a>

                    <ul class="submenu">
                        <php>getsubmenu1($menu['items'])</php>
                    </ul>
                <php>}</php>

            </li>

        <php>}</php>
    </notempty>
    <php>}</php>

    <php>function getsubmenu1($submenus){</php>
    <php>foreach($submenus as $menu){</php>
    <li>
        <php>
            $menu_name=lang($menu['lang']);
            $menu_name=$menu['lang']==$menu_name?$menu['name']:$menu_name;
        </php>
        <php>if(empty($menu['items'])){</php>
        <a href="javascript:openapp('{$menu.url}','{$menu.id}','{$menu_name}',true);" class="nav-link">
            <i class="fa fa-caret-right"></i>
            <span class="menu-text">
                                    {$menu_name}
                                </span>
        </a>
        <php>}else{</php>

        <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">
            <i class="fa fa-caret-right"></i>
            <span class="menu-text">
                                    {$menu_name}
                                </span>
            <b class="arrow fa fa-angle-right"></b>
        </a>
        <ul class="submenu">
            <php>getsubmenu2($menu['items'])</php>
        </ul>
        <php>}</php>

    </li>

    <php>}</php>
    <php>}</php>

    <php>function getsubmenu2($submenus){</php>
    <php>foreach($submenus as $menu){</php>
    <li>
        <php>
            $menu_name=lang($menu['lang']);
            $menu_name=$menu['lang']==$menu_name?$menu['name']:$menu_name;
        </php>

        <a href="javascript:openapp('{$menu.url}','{$menu.id}','{$menu_name}',true);" class="nav-link">
            &nbsp;<i class="fa fa-angle-double-right"></i>
            <span class="menu-text">
                                {$menu_name}
                            </span>
        </a>
    </li>

    <php>}</php>
    <php>}</php>
</block>

<extend name="public@frametemplate"/>
<block name="style">
        <style>
        .nav-list li{
            padding: 0;
            margin: 0;
            list-style: none;
        }
        .nav-list .submenu{
            padding: 0.5em;
        }
        
        .submenu{
            display: none;
        }
        .cmf-component-tabitem{
            position: relative;

            display: inline-block !important;
            float: none !important;
            min-width: 101px;
            text-align: center;
            cursor: pointer;
            vertical-align: top;
        }
        .cmf-component-tab {
            white-space: nowrap;
            float: left;
            margin: 0;
            display: inline-block !important;
        }
        #task-content{
                position: relative;
            float: left;
            overflow: hidden;
        }



        /*----------------导航hack--------------------*/
    </style>

    <script>
        //全局变量
        var GV = {
            HOST: "{$_SERVER['HTTP_HOST']}",
            ROOT: "__ROOT__/",
            WEB_ROOT: "__WEB_ROOT__/",
            JS_ROOT: "static/js/"
        };
    </script>
</block>
<block name="lefttopnav">
    <div class="sidebar-shortcuts" id="sidebar-shortcuts">


            <if condition="cmf_auth_check(cmf_get_current_admin_id(),'user/AdminAsset/index')">
                <a class="btn btn-sm btn-info"
                   href="javascript:openapp('{:url('user/AdminAsset/index')}','userAdminAssetindex','资源管理',true);"
                   title="资源管理"
                   data-toggle="tooltip">
                    <i class="fa fa-file"></i>
                </a>
            </if>

            <if condition="cmf_auth_check(cmf_get_current_admin_id(),'admin/Setting/clearcache')">
                <a class="btn btn-sm btn-danger"
                   href="javascript:openapp('{:url('admin/Setting/clearcache')}','index_clearcache','{:lang('ADMIN_SETTING_CLEARCACHE')}',true);"
                   title="{:lang('ADMIN_SETTING_CLEARCACHE')}"
                   data-toggle="tooltip">
                    <i class="fa fa-trash-o"></i>
                </a>
            </if>

            <if condition="cmf_auth_check(cmf_get_current_admin_id(),'admin/RecycleBin/index')">
                <a class="btn btn-sm btn-danger"
                   href="javascript:openapp('{:url('admin/RecycleBin/index')}','index_recycle','回收站',true);"
                   title="回收站"
                   data-toggle="tooltip">
                    <i class="fa fa-recycle"></i>
                </a>
            </if>

            <if condition="APP_DEBUG">
                <a class="btn btn-sm btn-default"
                   href="javascript:openapp('{:url('admin/Menu/index')}','index_menu','{:lang('ADMIN_MENU_INDEX')}',true);"
                   title="{:lang('ADMIN_MENU_INDEX')}"
                   data-toggle="tooltip">
                    <i class="fa fa-list"></i>
                </a>
            </if>

        </div>    
</block>
<block name="leftnav">
    {:getsubmenu($submenus)}
</block>


<block name="script">
<script src="__STATIC__/js/admin.js"></script>
<script src="__TMPL__/public/assets/js/adminindex.js"></script>
<script>
    $(function () {
        $("[data-toggle='tooltip']").tooltip();
        $("li.dropdown").hover(function () {
            $(this).addClass("open");
        }, function () {
            $(this).removeClass("open");
        });

        var menus= {:$menus_js_var};
        //读取url参数。尝试执行菜单功能。
        if(typeof(menus) != "undefined"){

            var tw = window.top;
            var twa =tw.location.href.split("#");
            var url = twa[1];
            var urlTmp = url;
            if (url !=null ){
                //去掉/ 去掉_ 全部小写。
                urlTmp = urlTmp.replace(/[\\/|_|]/g,"");
                urlTmp = urlTmp.replace(".html","");
                var menu = menus[urlTmp];
                if (menu){
                    openapp(url,menu.id+menu.app,menu.name,true);
                }
            }
        }




    });

    var ismenumin = $("#sidebar").hasClass("menu-min");
    $(".nav-list").on("click", function (event) {
        var closest_a = $(event.target).closest("a");
        if (!closest_a || closest_a.length == 0) {
            return
        }
        if (!closest_a.hasClass("dropdown-toggle")) {
            if (ismenumin && "click" == "tap" && closest_a.get(0).parentNode.parentNode == this) {
                var closest_a_menu_text = closest_a.find(".menu-text").get(0);
                if (event.target != closest_a_menu_text && !$.contains(closest_a_menu_text, event.target)) {
                    return false
                }
            }
            return
        }
        var closest_a_next = closest_a.next().get(0);
        if (!$(closest_a_next).is(":visible")) {
            var closest_ul = $(closest_a_next.parentNode).closest("ul");
            if (ismenumin && closest_ul.hasClass("nav-list")) {
                return
            }
            closest_ul.find("> .open > .submenu").each(function () {
                if (this != closest_a_next && !$(this.parentNode).hasClass("active")) {
                    $(this).slideUp(150).parent().removeClass("open")
                }
            });
        }
        if (ismenumin && $(closest_a_next.parentNode.parentNode).hasClass("nav-list")) {
            return false;
        }
        $(closest_a_next).slideToggle(150).parent().toggleClass("open");
        return false;
    });



</script>

</block>

<block name="content">
    <div class="page-content" id="content">
        <iframe src="{:url('Main/index')}" style="width:100%;height: 100%;" frameborder="0" id="appiframe-0"
                    class="appiframe"></iframe>
    </div>
</block>

